package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbQr;
import com.ruoyi.system.service.ITbQrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 二维码信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/business/qr")
public class TbQrController extends BaseController
{
    @Autowired
    private ITbQrService tbQrService;

    /**
     * 查询二维码信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbQr tbQr)
    {
        startPage();
        List<TbQr> list = tbQrService.selectTbQrList(tbQr);
        return getDataTable(list);
    }

    /**
     * 导出二维码信息列表
     */
    @Log(title = "二维码信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbQr tbQr)
    {
        List<TbQr> list = tbQrService.selectTbQrList(tbQr);
        ExcelUtil<TbQr> util = new ExcelUtil<TbQr>(TbQr.class);
        util.exportExcel(response, list, "二维码信息数据");
    }

    /**
     * 获取二维码信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbQrService.selectTbQrById(id));
    }

    /**
     * 新增二维码信息
     */
    @Log(title = "二维码信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbQr tbQr)
    {
        return toAjax(tbQrService.insertTbQr(tbQr));
    }

    /**
     * 修改二维码信息
     */
    @Log(title = "二维码信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbQr tbQr)
    {
        return toAjax(tbQrService.updateTbQr(tbQr));
    }

    /**
     * 删除二维码信息
     */
    @Log(title = "二维码信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbQrService.deleteTbQrByIds(ids));
    }
}
